package com.kotlin.tsw.kotlinmall.ui.adapter

import android.content.Context
import android.support.v4.view.PagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kotlin.base.utils.GlideUtils
import com.kotlin.tsw.kotlinmall.R
import kotlinx.android.synthetic.main.layout_topic_item.view.*

class TopicAdapter(private val context: Context, private val list: List<String>) : PagerAdapter() {
    override fun isViewFromObject(p0: View, p1: Any): Boolean {
        return p0 == (p1 as View)
    }

    override fun getCount(): Int {
        return this.list.size
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val root = LayoutInflater.from(context).inflate(R.layout.layout_topic_item, container, false)
        GlideUtils.loadUrlImage(context,list[position],root.mTopicIv)
        container.addView(root)
        return root
    }
}